<template>
  <el-card class="box-card">
    <template #header>
      <span class="title">账号中心</span>
    </template>

    <el-form label-width="80px">
      <el-form-item label="账号">{{ payload.username }}</el-form-item>
      <el-form-item label="角色">{{ roleText }}</el-form-item>
      <el-form-item label="所属门店" v-if="payload.role !== 1">
        {{ payload.storeName || '—' }}
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="pwdDlg.open()">修改密码</el-button>
      </el-form-item>
    </el-form>
  </el-card>

  <!-- 弹窗 -->
  <PasswordDialog ref="pwdDlg" />
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ref } from 'vue'
import { jwtDecode } from 'jwt-decode'
import { useAuthStore } from '@/stores/auth'
import PasswordDialog from '@/components/PasswordDialog.vue'

interface JwtPayload{ username:string; role:1|2|3|4; storeName?:string }
const auth = useAuthStore()
const payload = computed<JwtPayload>(() =>
  auth.token ? jwtDecode<JwtPayload>(auth.token) : {} as JwtPayload)
const roleText = computed(()=> ['顾客','服务员','店长','管理员'][payload.value.role-1])

const pwdDlg = ref()
</script>